package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.Sql.SqlProvider;
import com.baseweb.webadmin.core.model.bvo.ByUserOrderEvaluatvo;
import com.baseweb.webadmin.core.model.bvo.ByUserOrderInfoBvo;
import com.baseweb.webadmin.core.model.pojo.ByUserOrder;
import com.baseweb.webadmin.core.model.pojo.ByUserOrderExample;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.joda.time.DateTime;

public interface ByUserOrderMapper {
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    int countByExample(ByUserOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    int deleteByExample(ByUserOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    @Delete({
        "delete from by_user_order",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer id);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    @Insert({
        "insert into by_user_order (user_id, pay_type, ",
        "price, coins, create_time, ",
        "update_time, ",
        "descn, status, order_type, ",
        "biz_comment, user_comment, ",
        "biz_stars, user_stars, ",
        "voucher, deposit, ",
        "need_pay_price, alipayNotifyTime, ",
        "alipayNotifyType, alipayNotifyId, ",
        "alipayTradeNo, alipayTradeStatus, ",
        "alipaySellerId, alipaySellerEmail, ",
        "alipayTotalFee, alipayGmtCreate, ",
        "alipayGmtPayment, ",
        "weiXinOrderId, weiXinBankType, ",
        "weiXinFeeType, weiXinTimer, ",
        "weiXinTradeType, weiXinOpenid, ",
        "weiXinSign, weiXinCashFee, ",
        "weiXinCashFeeType, weiXinIsSubscribe, ",
        "pay_status, biz_user_id,refundDesn, ",
        "evaluation_time,imgUrl,red_packet_money)",
        "values (#{userId,jdbcType=INTEGER}, #{payType,jdbcType=INTEGER}, ",
        "#{price,jdbcType=DECIMAL}, #{coins,jdbcType=INTEGER}, #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{descn,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, #{orderType,jdbcType=INTEGER}, ",
        "#{bizComment,jdbcType=VARCHAR}, #{userComment,jdbcType=VARCHAR}, ",
        "#{bizStars,jdbcType=INTEGER}, #{userStars,jdbcType=INTEGER}, ",
        "#{voucher,jdbcType=DECIMAL}, #{deposit,jdbcType=DECIMAL}, ",
        "#{needPayPrice,jdbcType=DECIMAL}, #{alipaynotifytime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{alipaynotifytype,jdbcType=VARCHAR}, #{alipaynotifyid,jdbcType=VARCHAR}, ",
        "#{alipaytradeno,jdbcType=VARCHAR}, #{alipaytradestatus,jdbcType=VARCHAR}, ",
        "#{alipaysellerid,jdbcType=VARCHAR}, #{alipayselleremail,jdbcType=VARCHAR}, ",
        "#{alipaytotalfee,jdbcType=DECIMAL}, #{alipaygmtcreate,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{alipaygmtpayment,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{weixinorderid,jdbcType=VARCHAR}, #{weixinbanktype,jdbcType=VARCHAR}, ",
        "#{weixinfeetype,jdbcType=VARCHAR}, #{weixintimer,jdbcType=VARCHAR}, ",
        "#{weixintradetype,jdbcType=VARCHAR}, #{weixinopenid,jdbcType=VARCHAR}, ",
        "#{weixinsign,jdbcType=VARCHAR}, #{weixincashfee,jdbcType=INTEGER}, ",
        "#{weixincashfeetype,jdbcType=VARCHAR}, #{weixinissubscribe,jdbcType=VARCHAR}, ",
        "#{payStatus,jdbcType=INTEGER}, #{bizUserId,jdbcType=INTEGER}, #{refundDesn,jdbcType=VARCHAR},",
        "#{evaluationTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler}, ",
        "#{imgUrl,jdbcType=VARCHAR},#{redPacketMoney,jdbcType=DECIMAL})"
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    int insert(ByUserOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    int insertSelective(ByUserOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    List<ByUserOrder> selectByExample(ByUserOrderExample example);

    @SelectProvider(type = SqlProvider.class,method = "selectOrderPageSql")
    @ResultMap("OrderManageUnion")
    List<ByUserOrderInfoBvo> selectOrderListByPage(@Param("userId")Integer userId,@Param("area")String area, @Param("guserId")Integer guserId,@Param("bizUserId")Integer bizUserId, @Param("status")Integer status, @Param("payStatus")Integer payStatus,@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("order")ByUserOrderInfoBvo order,@Param("professionName")String professionName, @Param("start")Integer start, @Param("offset")Integer offset);


    @SelectProvider(type = SqlProvider.class,method = "sumPriceFromOrder")
    @ResultMap("OrderManageUnion")
    ByUserOrderInfoBvo sumPriceFromOrder(@Param("userId")Integer userId,@Param("area")String area, @Param("guserId")Integer guserId,@Param("bizUserId")Integer bizUserId, @Param("status")Integer status, @Param("payStatus")Integer payStatus,@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("order")ByUserOrderInfoBvo order,@Param("professionName")String professionName, @Param("start")Integer start, @Param("offset")Integer offset);

    @SelectProvider(type = SqlProvider.class,method = "selectOrderEvaluatSql")
    @ResultMap("ByUserOrderEvaluat")
    List<ByUserOrderEvaluatvo> selectOrderEvaluatvoListByPage(@Param("userOrder")ByUserOrder userOrder, @Param("start")Integer start, @Param("offset")Integer offset);

    @SelectProvider(type = SqlProvider.class, method = "selectOrderEvaluatSql")
    Integer selectOrderEvaluatvoListTotal(@Param("userOrder")ByUserOrder userOrder);

    @SelectProvider(type = SqlProvider.class,method = "selectOrderCountSql")
    Integer selectOrderListByBizUserCount(@Param("userId")Integer userId,@Param("area")String area, @Param("guserId")Integer guserId, @Param("bizUserId")Integer bizUserId, @Param("status")Integer status, @Param("payStatus")Integer payStatus,@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("professionName")String professionName,@Param("order")ByUserOrderInfoBvo order);

    @SelectProvider(type = SqlProvider.class,method = "selectOrderCountSql")
    Integer selectOrderListByBizUserCountzOfEvalution(@Param("userId")Integer userId, @Param("bizUserId")Integer bizUserId, @Param("status")Integer status, @Param("payStatus")Integer payStatus,@Param("startTime")String startTime,@Param("endTime")String endTime,@Param("professionName")String professionName,@Param("order")ByUserOrderInfoBvo order);


    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    @Select({
        "select",
        "id, user_id, pay_type, price, coins, create_time, update_time, descn, status, ",
        "order_type, biz_comment, user_comment, biz_stars, user_stars, voucher, deposit, ",
        "need_pay_price, alipayNotifyTime, alipayNotifyType, alipayNotifyId, alipayTradeNo, ",
        "alipayTradeStatus, alipaySellerId, alipaySellerEmail, alipayTotalFee, alipayGmtCreate, ",
        "alipayGmtPayment, weiXinOrderId, weiXinBankType, weiXinFeeType, weiXinTimer, ",
        "weiXinTradeType, weiXinOpenid, weiXinSign, weiXinCashFee, weiXinCashFeeType, ",
        "weiXinIsSubscribe, pay_status, biz_user_id, red_packet_money,imgUrl,refundDesn",
        "from by_user_order",
        "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    ByUserOrder selectByPrimaryKey(Integer id);

    @Select({
            "select o.status from by_user_order o join by_user_order_detail od on o.id = od.order_id",
            " where od.product_id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    List<ByUserOrder> selectOrderByProductId(Integer id);

    @Select({
            "select count(1) from by_user_biz_schedule ",
            "where schedule_type = #{type, jdbcType=VARCHAR} and user_id = #{userId, jdbcType=INTEGER} ",
            "and schedule_date = #{schedule, jdbcType=DATE} and status = 1"
    })
    public int selectScheduleByUserId(@Param("userId") int userId, @Param("schedule") String scheduleDate, @Param("type") String scheduleType);

    /**
     * 根据用户ID与档期查询是否有未完成的订单
     * @param userId 用户ID
     * @param scheduleDate 档期
     * @return >0 - 有未完成的订单； 0 - 没有未完成的订单
     */
    @Select({
            "SELECT count(1) FROM by_user_order_detail d ",
            "LEFT JOIN by_user_order o ON o.id = d.order_id ",
            "WHERE d.biz_user_id = #{userId, jdbcType=INTEGER} AND d.schedule_date = #{scheduleDate, jdbcType=DATE} ",
            "AND dinner_type = #{scheduleType, jdbcType=VARCHAR} AND o.status IN(2, 4, 7)"
    })
    public int selectOrderUnfinished(@Param("userId") int userId, @Param("scheduleDate") String scheduleDate, @Param("scheduleType") String scheduleType);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    int updateByExampleSelective(@Param("record") ByUserOrder record, @Param("example") ByUserOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    int updateByExample(@Param("record") ByUserOrder record, @Param("example") ByUserOrderExample example);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    int updateByPrimaryKeySelective(ByUserOrder record);

    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table by_user_order
     *
     * @mbggenerated Mon Apr 03 14:13:48 CST 2017
     */
    @Update({
        "update by_user_order",
        "set user_id = #{userId,jdbcType=INTEGER},",
          "pay_type = #{payType,jdbcType=INTEGER},",
          "price = #{price,jdbcType=DECIMAL},",
          "coins = #{coins,jdbcType=INTEGER},",
          "create_time = #{createTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "evaluation_time = #{evaluationTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "update_time = #{updateTime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "descn = #{descn,jdbcType=VARCHAR},", "refundDesn = #{refundDesn,jdbcType=VARCHAR},",
          "status = #{status,jdbcType=INTEGER},",
          "order_type = #{orderType,jdbcType=INTEGER},",
          "biz_comment = #{bizComment,jdbcType=VARCHAR},",
          "user_comment = #{userComment,jdbcType=VARCHAR},",
          "biz_stars = #{bizStars,jdbcType=INTEGER},",
          "user_stars = #{userStars,jdbcType=INTEGER},",
          "voucher = #{voucher,jdbcType=DECIMAL},",
          "deposit = #{deposit,jdbcType=DECIMAL},",
          "need_pay_price = #{needPayPrice,jdbcType=DECIMAL},",
          "alipayNotifyTime = #{alipaynotifytime,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "alipayNotifyType = #{alipaynotifytype,jdbcType=VARCHAR},",
          "alipayNotifyId = #{alipaynotifyid,jdbcType=VARCHAR},",
          "alipayTradeNo = #{alipaytradeno,jdbcType=VARCHAR},",
          "alipayTradeStatus = #{alipaytradestatus,jdbcType=VARCHAR},",
          "alipaySellerId = #{alipaysellerid,jdbcType=VARCHAR},",
          "alipaySellerEmail = #{alipayselleremail,jdbcType=VARCHAR},",
          "alipayTotalFee = #{alipaytotalfee,jdbcType=DECIMAL},",
          "alipayGmtCreate = #{alipaygmtcreate,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "alipayGmtPayment = #{alipaygmtpayment,jdbcType=TIMESTAMP,typeHandler=com.baseweb.mybatis.typehandler.JodaDateTime2TimestampTypeHandler},",
          "weiXinOrderId = #{weixinorderid,jdbcType=VARCHAR},",
          "weiXinBankType = #{weixinbanktype,jdbcType=VARCHAR},",
          "weiXinFeeType = #{weixinfeetype,jdbcType=VARCHAR},",
          "weiXinTimer = #{weixintimer,jdbcType=VARCHAR},",
          "weiXinTradeType = #{weixintradetype,jdbcType=VARCHAR},",
          "weiXinOpenid = #{weixinopenid,jdbcType=VARCHAR},",
          "weiXinSign = #{weixinsign,jdbcType=VARCHAR},",
          "weiXinCashFee = #{weixincashfee,jdbcType=INTEGER},",
          "weiXinCashFeeType = #{weixincashfeetype,jdbcType=VARCHAR},",
          "weiXinIsSubscribe = #{weixinissubscribe,jdbcType=VARCHAR},",
          "imgUrl = #{imgUrl,jdbcType=VARCHAR},",
          "pay_status = #{payStatus,jdbcType=INTEGER},",
          "biz_user_id = #{bizUserId,jdbcType=INTEGER},",
          "red_packet_money = #{redPacketMoney,jdbcType=DECIMAL}",
        "where id = #{id,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(ByUserOrder record);

    @Select({
            "select",
            " count(*) from user u join by_user_order o on o.biz_user_id = u.id and o.user_stars is not null ",
            " where u.id = #{id,jdbcType=INTEGER}"
    })
    Integer countOrderDiscuss(@Param("id")Integer id);
}